package com.dream21th.common;

import com.dream21th.common.enums.RtnEnum;
import com.dream21th.common.utils.Dates;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class ComResp<T> {

    private String code;
    private String msg;
    private String responseNo;
    private String responseTime;
    private T responseData;

    public ComResp<T> success() {
        this.code = RtnEnum.OK.getCode();
        this.msg = RtnEnum.OK.getMessage();
        this.responseTime = Dates.getyyyyMMddHHmmssCurDate();
        return this;
    }

    public ComResp<T> result(String code, String msg) {
        this.code = code;
        this.msg = msg;
        this.responseTime = Dates.getyyyyMMddHHmmssCurDate();
        return this;
    }

    public ComResp<T> formRequest(ComReq<?> req) {
        this.responseNo = req.getRequestNo();
        return this;
    }

    public ComResp<T> responseNo(String responseNo) {
        this.responseNo = responseNo;
        return this;
    }


    public ComResp<T> data(T responseData) {
        this.responseData = responseData;
        return this;
    }

    public ComResp<T> result(RtnEnum rtnEnum) {
        this.code = rtnEnum.getCode();
        this.msg = rtnEnum.getMessage();
        this.responseTime = Dates.getyyyyMMddHHmmssCurDate();
        return this;
    }
}
